<template>
  <div class="wrap">
    <template v-if="step === 1">
      <Image name="status_icon/success" oss size="112" type="png" />
      <div class="mt48">合作申请书签署完成，等待企业审核...</div>
    </template>
    <template v-if="step === 2">
      <Image name="under_review" oss size="110" type="svg" />
      <div class="mt48 first_word">合作申请审核中</div>
      <div class="mt26">您的合作申请正在审核，可联系企业加快审核进度</div>
    </template>
  </div>
</template>

<script lang="ts" setup>
import { onLoad, onUnload, Router } from '@U/common'
import { ref } from 'vue'
import Image from '@C/Image.vue'
import { getProfileStatus } from '@P/Auth/request'
import { loginOK } from '@U/Auth'

const step = ref(1)
let checkTimer = 0
const getProfileStatusFn = () => {
  // 每次开启定时器前，清除上一次的定时器
  clearInterval(checkTimer)
  checkTimer = setInterval(async () => {
    const { code, data } = await getProfileStatus().finally(() => {})
    if (code === 200) {
      if (data.contractStatus === 1) {
        step.value = 2
        if (data.coopStatus === 2) await loginOK()
        if (data.coopStatus === 3) Router.reLaunch('signContract')
      } else if (data.contractStatus === 2) {
        if (data.coopStatus === 2) await loginOK()
      } else if (data.contractStatus === 3) {
        Router.reLaunch('signContract')
      }
    }
  }, 10000)
}
onLoad(() => {
  getProfileStatusFn()
})
onUnload(() => {
  clearInterval(checkTimer)
})
</script>

<style lang="less" scoped>
.wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: rgba(0, 0, 0, 0.85);
  font-size: 28rpx;
  padding-top: 260rpx;
  .first_word {
    font-size: 36rpx;
    font-weight: bolder;
  }
}
</style>
